class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


# Definition for singly-linked list.


class Solution:
    # def deleteDuplicates(self, head: ListNode) -> ListNode:
    def deleteDuplicates(self, head):
        if not head:
            return head
        h = head
        while not h.next:
            if h.val == h.next.val:
                h.next = h.next.next
            else:
                h = h.next
        return head
